﻿using System;

namespace Cpu6502.Opcodes
{
    public class JMP_A : Opcode
    {
        public JMP_A()
        {
            this.CpuCycles = 3;
            this.AddressType = CPU.AddressType.Absolute;
        }

        public override void Execute()
        {           
            // Set PC to new address
            CPU.PC = base.Argument;
        }
    }

    public class JMP_Indirect : Opcode
    {
        public JMP_Indirect()
        {
            this.CpuCycles = 5;
            this.AddressType = CPU.AddressType.IndirectAbsolute;
        }

        public override void Execute()
        {
            // 6502 uses a weird Indirect Addressing mode here.
            // It looks at low word of the passed address and the high word of the address next to it.
            // So if base.Arguments contains 0xEA and base.Arguments + 1 = 0x12 it would JMP to $12EA.   
            Int16 jmpPoint = (Int16)((CPU.Memory[base.Argument]) | (CPU.Memory[base.Argument + 1] << 8));
                      
            // Set PC to new address
            CPU.PC = jmpPoint;
        }
    }
}
